package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.impl.ProductSpecServiceImpl;
import com.atguigu.spzx.manager.entity.ProductSpec;
import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.manager.vo.productSpec.ProductSpecQueryRespVo;
import com.atguigu.spzx.manager.vo.productSpec.ProductSpecSaveReqVo;
import com.atguigu.spzx.manager.vo.productSpec.ProductSpecUpdateReqVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * ProductSpecController
 * </p>
 *
 * @author flyduck
 * @since 2023/10/30
 */
@Api(tags = "商品规格接口")
@RestController
@RequestMapping("/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    private ProductSpecServiceImpl productSpecService;

    @ApiOperation("查询所有商品规格")
    @GetMapping("/getProductSpecList")
    public Result getProductSpecList(){
        List<ProductSpecQueryRespVo> respVoList = productSpecService.getProductSpecList();
        return Result.ok(respVoList);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("/deleteProductSpecById/{id}")
    public Result deleteProductSpecById(@PathVariable Long id){
        productSpecService.deleteProductSpecById(id);
        return Result.ok();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/getProductSpecById/{id}")
    public Result getProductSpecById(@PathVariable Long id){
        ProductSpecQueryRespVo respVo = productSpecService.getProductSpecById(id);
        return Result.ok(respVo);
    }

    @ApiOperation("/修改")
    @PostMapping("/updateProductSpecById")
    public Result updateProductSpecById(@RequestBody ProductSpecUpdateReqVo reqVo){
        productSpecService.updateProductSpecById(reqVo);
        return Result.ok();
    }

    @ApiOperation("/添加")
    @PostMapping("/saveProductSpec")
    public Result saveProductSpec(@RequestBody ProductSpecSaveReqVo reqVo){
        productSpecService.saveProductSpec(reqVo);
        return Result.ok();
    }

    @ApiOperation("/分页查询")
    @GetMapping("/getProductSpecPage/{page}/{limit}")
    public Result getProductSpecPage(@PathVariable Integer page,
                       @PathVariable Integer limit){
        Page<ProductSpec> pageParam = new Page<>(page, limit);
        Page<ProductSpecQueryRespVo> pageModel = productSpecService.getProductSpecPage(pageParam);
        return Result.ok(pageModel);
    }
}
